#ifndef MOUSEUTILS_H
#define MOUSEUTILS_H

#include "includes.h"
#include "chunkmanager.h"
#include "cameramanager.h"

#define RAD_EPSILON 0.5
#define PLANE_DRAW_EPSILON 1.0

class MouseUtils
{
    ChunkManager* chunky;
    CameraManager* Camera;

public:
    MouseUtils(ChunkManager* c, CameraManager* cam);
    vector3<float> get3DFrom2D(float x, float y);
    vector3<int> March(vector3<float> eye, vector3<float> lookat, float d=-1.0);
    vector3<int> getMouseOverVoxelPt(float x, float y, float d=-0.1);
    bool isMouseOverSphere(float x, float y, vector3<float> center, float radius);
};

inline
vector3<int> MouseUtils::getMouseOverVoxelPt(float x, float y, float d){
    vector3<float> lookAt = get3DFrom2D(x,y)-Camera->getEyeVector();
    return March(Camera->getEyeVector(),lookAt,d);
}

inline
bool MouseUtils::isMouseOverSphere(float x, float y, vector3<float> center, float radius){
     vector3<float> pt = get3DFrom2D(x,y);
     return (pt-center).mag() <= (radius+RAD_EPSILON);
}

#endif // MOUSEUTILS_H
